package com.metaera.app.controller.view;

import android.content.Context;
import android.content.Intent;

import com.metaera.app.controller.view.core.INetworkRequestView;
import com.metaera.app.data.model.HotSearchResponse;
import com.metaera.app.ui.activities.SearchActivity;
import com.sunfusheng.marqueeview.MarqueeView;

import java.util.ArrayList;
import java.util.List;

public class SearchHotMarqueeView implements INetworkRequestView<List<HotSearchResponse>> {

    private final MarqueeView<String> mMarqueeView;

    public SearchHotMarqueeView(MarqueeView<String> marqueeView) {
        this.mMarqueeView = marqueeView;
        // mMarqueeView.stopFlipping(); TODO: 页面不可见依旧执行动画
    }

    @Override
    public void successful(List<HotSearchResponse> result) {
        List<String> list = new ArrayList<>();
        for (HotSearchResponse response : result) {
            list.add(response.getTitle());
        }

        mMarqueeView.startWithList(list);
        mMarqueeView.setOnItemClickListener((position, textView) -> {
            Context context = textView.getContext();
            context.startActivity(new Intent(context, SearchActivity.class));
        });
    }

    @Override
    public void loading() {

    }

    @Override
    public void failure(Throwable throwable) {

    }

}
